﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FJASPX.Framwork.Model;
using FJASPX.Framwork.Query;
using NHibernate.Criterion;

namespace FJASPX.Framwork.Dao
{
    public abstract class NHEntityDao<T> : NHGenericDao, IEntityDao<T> where T : Entity
    {

        public virtual T Get(object id)
        {
            return base.Get<T>(id);
        }

        public virtual T SafeGet(object id)
        {
            return base.Get<T>(id);
        }
        public virtual void Save(T o)
        {
            base.InsertOrUpdate(o);
        }
        public virtual void Insert(T o)
        {
            base.Insert(o);
        }

        public virtual void Update(T o)
        {
            base.Update(o);
        }

        public virtual void Delete(T o)
        {
            base.Delete(o);
        }

        public virtual void DeleteById(object id)
        {
            base.DeleteById<T>(id);
        }
        public virtual void DeleteByIds(object[] ids)
        {
            base.DeleteByIds<T>(ids);
        }
        public virtual IList<T> GetAll()
        {
            return base.GetAll<T>();
        }
        public virtual IList<T> GetAll(string orderBy, bool isAsc)
        {
            return base.GetAll<T>(orderBy, isAsc);

        }
        #region"分页"
        public virtual Page PagedQuery(T example, int pageNo, int pageSize)
        {
            //TODO
            Page page = null;
            page = Page.EMPTY_PAGE;
            return page;

        }
        public virtual Page PagedQuery(int pageNo, int pageSize)
        {
            Page page = null;
            long recordCount = 0;
            List<object> data = (List<object>)this.Query<T>(pageNo, pageSize, out recordCount);
            int count = data.Count;
            if (recordCount == 0)
            {
                page = Page.EMPTY_PAGE;
            }
            else
            {
                page = new Page(pageNo, recordCount, pageSize, data);
            }
            return page;
        }
        public virtual Page PagedQuery(ICriterion criteria, int pageNo, int pageSize)
        { //TODO
            Page page = null;
            page = Page.EMPTY_PAGE;
            return page;
        }
        public virtual Page PagedQuery(int pageNo, int pageSize, ICriterion[] criterion)
        {
            //TODO
            Page page = null;
            page = Page.EMPTY_PAGE;
            return page;
        }
        public virtual Page PagedQuery(int pageNo, int pageSize, string orderBy, bool isAsc, ICriterion[] criterion)
        {
            //TODO
            Page page = null;
            page = Page.EMPTY_PAGE;
            return page;
        }
        public virtual Page PagedQuery(string hql, int pageNo, int pageSize, object[] values)
        {
            //TODO
            Page page = null;
            page = Page.EMPTY_PAGE;
            return page;
        }

        #endregion
    }
}
